import pandas as pd
from prophet import Prophet

if __name__ == '__main__':
    # 导入数据，该数据包含两列【ds，y】
    data_frame = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv')
    data_frame.head()

    # 创建模型
    model = Prophet()
    # 传入数据并训练
    model.fit(data_frame)

    # 创建预测趋势（30 天）
    future = model.make_future_dataframe(periods=5)
    # 打印后五条
    print(future.tail())
    # 进行数据预测
    forecast = model.predict(future)
    # 按列打印后五条
    print(forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail())

    # 保存预测数据
    forecast.to_csv('./tmp/forecast.csv')

    # 按日展示
    fig1 = model.plot(forecast)
    fig1.show()
    # 按节假日展示
    fig2 = model.plot_components(forecast)
    fig2.show()
